import { defineStore, _GettersTree } from 'pinia'

/**AppState模型 */
export interface AppState {
	/**数量 */
	counter: number
}
/**AppGetters模型 */
export interface AppGetters extends _GettersTree<AppState> {
	/**获取双倍数量 */
	doubleCount(state:AppState): number
}

export const useAppStore = defineStore('app', {
	state: ():AppState => ({
	 	counter: 0,
	}),
	getters:{
		doubleCount(state) {
			return state.counter * 2
		}
	} as AppGetters,
	actions: {
		/**增加 */
		add(num: number) {
			this.counter+=num
		},
		/**随机数字 */
		randomizeCounter() {
			this.counter = Math.round(100 * Math.random())
		},
	},
})
